<?php
/**
 *
 * IndexAction.class.php (前台首页)
 *
 */
if (!defined("Yourphp")) {
	exit("Access Denied");
}

class IndexAction extends BaseAction {
	public function index() {
		$this->assign('bcid', 0); //顶级栏目
		$this->assign('ishome', 'home');
		
		$map['posid']="1";
		$map['status']='1';
		$model=M("Product");
		$recommend=$model->where($map)->order("updatetime desc,listorder desc")->limit(8)->select();

		$hotmap['status']='1';
		$hotproduct=$model->where($hotmap)->order("updatetime desc,listorder desc")->limit(8)->select();

		
		$this->assign("recommend",$recommend);
		$this->assign('hotproduct',$hotproduct);
		
		$this->display();
	}

	public function getHotProduct(){
		$cid=intval($_REQUEST['cid']);

		$map['catid']=($cid==0)?"":$cid;
		$map['posid']="1";
		$map['status']='1';
		$model=M("Product");
		$recommend=$model->where($map)->order("updatetime desc,listorder desc")->limit(9)->select();
		$count=$model->where($map)->count();

		if($count<=9){
			$count=9-$count;
			$map['posid']=array('neq',1);
			$hotproduct=$model->where($map)->order("updatetime desc,listorder desc")->limit($count)->select();
		}else{
			$hotproduct=0;
		};		
		
		$data['recommend']=$recommend;
		$data['hotproduct']=$hotproduct;
		$this->ajaxReturn($data);
	}

}
?>